package com.vq.config;

//import com.vq.controller.interceptor.ProjectInterceptor;
import com.vq.interceptor.ControllerInterceptor;
import com.vq.util.EmailUtil;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.servlet.MultipartConfigElement;

@Configuration
@Import({EmailUtil.class, ControllerInterceptor.class})
public class SpringConfig {
    @Bean
    public PasswordEncoder passwordEncoder() {
        //使用默认的BCryptPasswordEncoder加密方案
        return new BCryptPasswordEncoder();
    }

    @Bean
    public MultipartConfigElement getMultipartConfig() {
        MultipartConfigFactory config = new MultipartConfigFactory() ;
        return config.createMultipartConfig() ;	// 创建一个上传配置
    }

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(RestClient.builder(HttpHost.create("127.0.0.1:9200")));
    }

}
